package com.elinkway.infinitemovies.bigdata;

import android.text.TextUtils;

import com.lvideo.http.bean.LVideoBaseBean;
import com.lvideo.http.bean.LVideoDataHull;

/**
 * Created by wangyemin on 2015/11/18.
 */

/**
 * 广告日常上报
 */
public class BigDataAdActionTask extends BigDataBaseTask {
    /**
     * 设置acode
     *
     * @param acode {@link BigDataConstants#ACODE_CLICK},
     *              {@link BigDataConstants#ACODE_EXPOSURE},
     * @return
     */
    public BigDataAdActionTask setAcode(String acode) {
        putParam("acode", acode);
        return this;
    }

    /**
     * 设置ap
     *
     * @param ap
     * @return
     */
    public BigDataAdActionTask setAp(String ap) {
        putParam("ap", ap);
        return this;
    }

    /**
     * 事件结果
     *
     * @param ar {@link BigDataConstants#AR_FAILED},
     *           {@link BigDataConstants#AR_SUCCESS}
     * @return
     */
    public BigDataAdActionTask setAR(String ar) {
        putParam("ar", ar);
        return this;
    }

    /**
     * 设置网络类型
     *
     * @param netType
     * @return
     */
    public BigDataAdActionTask setNT(String netType) {
        putParam("nt", netType);
        return this;
    }


    /**
     * 检测参数
     *
     * @return
     */
    public boolean checkArgs() {
        String message = "";
        LogUtils.d("post action is ready to go, params:" + params.toString());
//        if (TextUtils.isEmpty(getParam("ar"))) {
//            message = "ar is null,  call setAR(ar) first.";
//        } else
        if (TextUtils.isEmpty(getParam("ap"))) {
            message = "ap is null, you should call following methods : setAp";
        } else if (TextUtils.isEmpty(getParam("acode"))) {
            message = "acode is null, call setAcode(acode) first. ";
        } else if (TextUtils.isEmpty(getParam("nt"))) {
            message = "nt is null, call setNT(nt) first. ";
        }
        if (!TextUtils.isEmpty(message)) {
            LogUtils.w(message);
            return false;
        }
        return true;
    }

    @Override
    public boolean execute() {
        if (checkArgs()) {
            LVideoDataHull<LVideoBaseBean> d = BigDataApi.postAdAction(null, getParam("ap"), getParam("ar"), getParam("acode"), getParam("nt"));
            return d.getDataType() == LVideoDataHull.DataType.DATA_PARSER_IS_NULL;
        }
        return false;
    }
}
